<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;
use App\Models\Order;

class OrderController extends Controller
{
    //订单管理
    public function index(){
        $priceSum = number_format(DB::table('cdorder')->where('pay_status',1)->sum('price') ,2, '.', '');
        $data = DB::table('cdorder')->orderBy('add_time', 'desc')->paginate(15);
    return view('admin.order.index',compact('data','priceSum'));
      }

    //单条订单查询
    public function indexp(Request $request){
    $priceSum = DB::table('cdorder')->where('pay_status',1)->sum('price');
    $data = DB::table('cdorder')->where('order_sn',$request->order_sn)->paginate(15);
    return view('admin.order.index',compact('data','priceSum'));
      }


//删除
public function destroy($order_id)
    {

      $post = DB::table('cdorder')->where('order_id', $order_id)->delete(['is_del'=>1]);
      return  $data = ['status' => 0,'msg' => '删除成功！'];
    }

//搜索提交
    public function store(Request $request){
          $search = $request->keyword;
          $type = $request->stype;
          if ($type == 0) {
            $data = DB::table('cdorder')->orderBy('add_time', 'desc')
                              ->where('order_sn', 'like', '%'.$search.'%')
                              ->get();
          }else{
             $data = DB::table('cdorder')->orderBy('add_time', 'desc')
                              ->where('uid', 'like', '%'.$search.'%')
                              ->get();
          }

    return view('admin.order.index',compact('data'));
    }

}
